package practice_0527;

public class practice06 {
    public static void main(String[] args) {
        cash cash = new cash();
        new Thread(cash).start();
        new Thread(cash).start();
        new Thread(cash).start();

    }
}
class cash implements Runnable{
    private static int total_money = 100;
    @Override
    public void run() {
        while(true){
            synchronized(this)
            {
                if (total_money <= 0) {
                    System.out.println("余额不足！");
                    break;
                }
                System.out.println(Thread.currentThread().getName() + "取走了1000，余额为：" + (total_money -= 1));
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}

